//Accepted
#include <cstdio>
void rec(int x){
	if(x){
		rec(x/3);
		printf("%d", x%3);
	}
}
int main(){
	// freopen("in.txt","r",stdin);
	int n;
	scanf("%d", &n);
	while(n>=0){
		if(n){
			rec(n);
			printf("\n");
		}else printf("0\n");
		scanf("%d", &n);
	}
	return 0;
}
